<template>
	<div>
		<el-form :model="form.editUserPwdInfo" :rules="rules.editUserPwdInfo" ref="form" style="width: 400px;margin: 50px 100px" >
			
			<!--<el-form-item label="原密码" :label-width="formLabelWidth" prop="old_pwd">-->
		      <!--<el-input type="password" v-model="form.editUserPwdInfo.old_pwd" style="width: 300px"></el-input>-->
			<!--</el-form-item>-->

			<el-form-item label="新密码" :label-width="formLabelWidth" prop="new_pwd1">
		      <el-input type="password" v-model="form.editUserPwdInfo.new_pwd1" style="width: 300px"></el-input>
			</el-form-item>

			<el-form-item label="密码确认" :label-width="formLabelWidth" prop="new_pwd2">
		      <el-input type="password" v-model="form.editUserPwdInfo.new_pwd2" style="width: 300px"></el-input>
			</el-form-item>
			<div  style="margin-left:120px">
				<el-button type="primary" @click="editUserPwd('form')">修 改</el-button>
			</div>
		</el-form>
	</div>
</template>
<script>
import _http from '../common/http.vue'
export default{
	data(){
		return {
			userid:'',
			form:{
				editUserPwdInfo:{
					userId:'',
					old_pwd:'',
					new_pwd1:'',
					new_pwd2:''
				}
			},
			apiPort:{
//				分页数据接口
				roleList:'system/updatePwd',
			},
			rules:{
				editUserPwdInfo:{
//					old_pwd:[{required:true,message:'请填写原密码'}],
					new_pwd1:[{required:true,message:'请填写新密码'}],
					new_pwd2:[{required:true,message:'请填写新密码'}],
				}
			},
			formLabelWidth:'120px'
		}
	},
	mounted(){
		this.form.editUserPwdInfo.userId = localStorage.getItem('userId')
		this.userid=localStorage.getItem('userId')
		this.form.editUserPwdInfo.userid = localStorage.getItem('userId')
	},
	methods:{
		editUserPwd(formName){
			var that = this
			this.$refs[formName].validate((valid) => {
				if (!valid) {return false}
				if (that.form.editUserPwdInfo.new_pwd1 !== that.form.editUserPwdInfo.new_pwd2) {
					that.$message.error('两次密码输入不一致');
					return false;
				}
			that.form.editUserPwdInfo.userid=that.userid
			var params = that.querystring.stringify({userid:that.userid,newpassword:that.form.editUserPwdInfo.new_pwd2})
			_http.axiosRequest(that,that.apiPort.roleList,params,(res)=>{
				console.log(res.data)
			if(res.data.code==100){
				that.$message({
					message:'密码修改成功',
					type:'success'
				})
//				window.location.href="/"
			}else{
				that.$message({
					message:'密码修改失败',
					type:'waring'
				})
			}

		})
			})
			
		}
	}
}	
</script>
<style>
.dialog-footer{
	text-align: center;
}	
</style>